package com.zzyl.controller;

import com.zzyl.base.NursingProject;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("护理项目分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> searchByPage(@ApiParam(value = "项目名称") String name,
                                                                       @ApiParam(value = "状态：0-禁用，1-启用")  Integer status,
                                                                       @ApiParam(value = "当前页码") @RequestParam(defaultValue = "1",required = false)Integer pageNum,
                                                                       @ApiParam(value = "每页数量") @RequestParam(defaultValue = "10",required = false)Integer pageSize){
        PageResponse<NursingProjectVo> result = nursingProjectService.searchByPage(name, status, pageNum, pageSize);

        return ResponseResult.success(result);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult addNursing(@RequestBody NursingProjectDto npj){

        nursingProjectService.addNursing(npj);

        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingProjectVo> search(@ApiParam(value = "项目id",required = true) @PathVariable Long id){
        NursingProject nursingProject = nursingProjectService.search(id);

        return ResponseResult.success(nursingProject);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);

        return ResponseResult.success();
    }
}
